#pragma warning(disable : 4996)
#include"ListNode.h";
void init(ListNode* head)
{
	head->val = 0;
	head->pre = head;
	head->next = head;

}
void ListDestory(ListNode* head)
{
	ListNode* tail = head->pre;
	while (tail != head)
	{
		tail = tail->pre;
		free(tail->next);
		tail->next =NULL ;

	}
	


}
void ListPrint(ListNode* head)
{
	ListNode* tail = head->next;
	while (tail!=head)
	{
		printf("%d<=>", tail->val);
		tail = tail->next;

	}
	printf("\n");



}
ListNode* BuyNode()
{
	ListNode* newnode = (ListNode*)malloc(sizeof(ListNode));
	if (newnode == NULL)
	{
		perror("newnode=NULL");
	}
	return newnode;

}
void ListPushBack(ListNode* head,int x)
{
	ListNode* newnode = BuyNode();
	newnode->val = x;
	ListNode* tail= head->pre;
	tail->next = newnode;
	newnode->pre = tail;
	newnode->next = head;
	head->pre = newnode;



}
void ListPopBack(ListNode* head)
{
	assert(head->next != head);
	ListNode* tail = head->pre->pre;
	tail->next = head;
	free(head->pre);
	head->pre = tail;
}
ListNode* ListFind(ListNode* head, int x)
{
	ListNode* tail = head;
	assert(tail->next != head);
	tail = tail->next;
	while (tail != head)
	{
		if (tail->val == x)
		{
			return tail;
		}
		tail = tail->next;
	}
	return NULL;
}
void ListInsert(ListNode* pos, int x)
{
	assert(pos != NULL);
	ListNode* newnode = BuyNode();
	ListNode* tail = pos->pre;
	newnode->val = x;
	tail->next = newnode;
	pos->pre = newnode;
	newnode->pre = tail;
	newnode->next = pos;
}
;
void Listpop(ListNode* pos)
{
	ListNode* pre = pos->pre;
	ListNode* next = pos->next;
	free(pre->next);
	pre->next = next;
	next->pre = pre;
}